#pragma once
#include "logger_api.hpp"
#include "metrics/metrics_collector.hpp"
#include <string>

class MetricsSinkDecorator : public ISink {
public:
    MetricsSinkDecorator(std::shared_ptr<ISink> target, std::string name) 
        : m_target(std::move(target)) 
        , m_name(std::move(name)) {}

    void log(LogLevel level, const std::string& formatted_message) override {
        try {
            m_target->log(level, formatted_message);
        } catch (const std::exception& e) {
            // 捕获Sink写入异常， 记录错误数
            get_metrics_collector()->inc_sink_errors(m_name);
            throw; // 继续抛出异常，由上层处理
        }
    }

    std::string getName() override {
        return m_target->getName();
    }

private:
    std::shared_ptr<ISink> m_target;
    std::string m_name;
};

